<?php

getTicketList();
while (1){
    sleep(4);

    exec('say "d"');

    $jsonString = file_get_contents($argv[1]);
    $json_Array = json_decode($jsonString,true);

    $remainMap = getTicketList();
    //
    var_dump("查询余票：".json_encode($remainMap));

    //DAY2 vip
    if($remainMap["1905"] >0 ){
        //
        $buyerList = getBuyerList();
        var_dump("查询购买人列表：".json_encode($buyerList));
    }

}

//获取余票数量
function getTicketList($params){
   $curl = curl_init();

   curl_setopt_array($curl, array(
     CURLOPT_URL => 'https://www.allcpp.cn/allcpp/ticket/getTicketTypeList.do?eventMainId=1074',
     CURLOPT_RETURNTRANSFER => true,
     CURLOPT_ENCODING => '',
     CURLOPT_MAXREDIRS => 10,
     CURLOPT_TIMEOUT => 0,
     CURLOPT_FOLLOWLOCATION => true,
     CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
     CURLOPT_CUSTOMREQUEST => 'GET',
       CURLOPT_HTTPHEADER=>$params["header"],
     //CURLOPT_HTTPHEADER => array(
       //  'authority: www.allcpp.cn',
       //     'accept: application/json, text/plain, */*',
       // 'accept-language: zh-CN,zh;q=0.9,en;q=0.8',
       //'cache-control: no-cache',
       // 'cookie: Hm_lvt_75e110b2a3c6890a57de45bd2882ec7c=1682046786; token=REvR5a13NVjGsMQ5vWEMLTtVTjNeF5gLIyUqI2a/M3c9M0rCE6wJ0Q0NhO2DJuXSzLur41+gYvQg1xi9D2TrhX+bgwef35sswtufzm8hA12Aywv84wBmTWcigueSaFahrptFE0s7ZFCk+fNX0m6uVUXBQV0Q1kc39259SQvKONg=; JALKSJFJASKDFJKALSJDFLJSF=2392071151b782ecc8ab784857bd845d3915e9a36f10.92.108.68_10522398; JSESSIONID=31CD3FDBBEB56AF9765434CE9EFD762C; Hm_lpvt_75e110b2a3c6890a57de45bd2882ec7c=1682090468; JSESSIONID=0CF896905391493F6D940AD463D1AC2F',
       //'origin: https://cp.allcpp.cn',
       //'pragma: no-cache',
       //'referer: https://cp.allcpp.cn/',
       //'sec-ch-ua: "Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
       //'sec-ch-ua-mobile: ?0',
       //'sec-ch-ua-platform: "macOS"',
       //'sec-fetch-dest: empty',
       //'sec-fetch-mode: cors',
       //'sec-fetch-site: same-site',
       //'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
       //),
   ));

   $response = curl_exec($curl);


   curl_close($curl);

   $json_Array=json_decode($response, true);
   $ticketTypeList = $json_Array["ticketTypeList"];

   foreach ($ticketTypeList as $key=>$val){
        $id = $val["id"];
        $remainderNum = $val["remainderNum"];
        $remainderNumMap[$id] = $remainderNum;
   }
   return $remainderNumMap;

}



//获取购票人列表
function getBuyerList($params){

    $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://www.allcpp.cn/allcpp/user/purchaser/getList.do',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'GET',
        CURLOPT_HTTPHEADER => array(
            'authority: www.allcpp.cn',
            'accept: application/json, text/plain, */*',
            'accept-language: zh-CN,zh;q=0.9,en;q=0.8',
            'cache-control: no-cache',
            'cookie: Hm_lvt_75e110b2a3c6890a57de45bd2882ec7c=1682046786; token=REvR5a13NVjGsMQ5vWEMLTtVTjNeF5gLIyUqI2a/M3c9M0rCE6wJ0Q0NhO2DJuXSzLur41+gYvQg1xi9D2TrhX+bgwef35sswtufzm8hA12Aywv84wBmTWcigueSaFahrptFE0s7ZFCk+fNX0m6uVUXBQV0Q1kc39259SQvKONg=; JALKSJFJASKDFJKALSJDFLJSF=2392071151b782ecc8ab784857bd845d3915e9a36f10.92.108.68_10522398; JSESSIONID=31CD3FDBBEB56AF9765434CE9EFD762C; Hm_lpvt_75e110b2a3c6890a57de45bd2882ec7c=1682087583; JSESSIONID=0CF896905391493F6D940AD463D1AC2F',
            'origin: https://cp.allcpp.cn',
            'pragma: no-cache',
            'referer: https://cp.allcpp.cn/',
            'sec-ch-ua: "Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
            'sec-ch-ua-mobile: ?0',
            'sec-ch-ua-platform: "macOS"',
            'sec-fetch-dest: empty',
            'sec-fetch-mode: cors',
            'sec-fetch-site: same-site',
            'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
        ),
        CURLOPT_HTTPHEADER=>$params["header"],
    ));

    $response = curl_exec($curl);

    curl_close($curl);

    $json_Array=json_decode($response, true);

    foreach ($json_Array as $key=>$val){
        $id = $val["id"];
        $remainderNum = $val["idcard"];
        $remainderNumMap[$id] = $remainderNum;
    }
    return $json_Array;
}

//下单
function BuyNow($tickId,$buyerId,$params ){
    $curl = curl_init();

    curl_setopt_array($curl, array(
        CURLOPT_URL => 'https://www.allcpp.cn/allcpp/ticket/buyTicketAlipay.do?ticketTypeId='.$tickId.'&count=1&nonce=bMxM4YKzKQ24Nz46NejHt4TZdjr6ZQ4C&timeStamp='.time().'&sign=cc286673d67e94627b22fe3e437e51f2&purchaserIds='.$buyerId,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS =>'{}',
        CURLOPT_HTTPHEADER => array(
            'authority: www.allcpp.cn',
            'accept: application/json, text/plain, */*',
            'accept-language: zh-CN,zh;q=0.9,en;q=0.8',
            'cache-control: no-cache',
            'content-type: application/json;charset=UTF-8',
            'cookie: Hm_lvt_75e110b2a3c6890a57de45bd2882ec7c=1682046786; token=REvR5a13NVjGsMQ5vWEMLTtVTjNeF5gLIyUqI2a/M3c9M0rCE6wJ0Q0NhO2DJuXSzLur41+gYvQg1xi9D2TrhX+bgwef35sswtufzm8hA12Aywv84wBmTWcigueSaFahrptFE0s7ZFCk+fNX0m6uVUXBQV0Q1kc39259SQvKONg=; JALKSJFJASKDFJKALSJDFLJSF=2392071151b782ecc8ab784857bd845d3915e9a36f10.92.108.68_10522398; JSESSIONID=31CD3FDBBEB56AF9765434CE9EFD762C; Hm_lpvt_75e110b2a3c6890a57de45bd2882ec7c=1682087583; JSESSIONID=0CF896905391493F6D940AD463D1AC2F',
            'origin: https://cp.allcpp.cn',
            'pragma: no-cache',
            'referer: https://cp.allcpp.cn/',
            'sec-ch-ua: "Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
            'sec-ch-ua-mobile: ?0',
            'sec-ch-ua-platform: "macOS"',
            'sec-fetch-dest: empty',
            'sec-fetch-mode: cors',
            'sec-fetch-site: same-site',
            'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
        ),
    ));

    $response = curl_exec($curl);

    curl_close($curl);

    $json_Array=json_decode($response, true);
    return $json_Array;
}

